import random
def guess_number():
    target_number = random.randint(0, 9)
    N = 0

    while True:
        try:
            user_input = input("请输入一个0~9之间的整数：")
            user_guess = int(user_input)
            N += 1

            if user_guess == target_number:
                print(f"预测{N}次，你猜中了！")
                break
            elif user_guess < target_number:
                print("遗憾，太小了")
            else:
                print("遗憾，太大了")

        except ValueError:
            print("user_guess is not number")
            break

if __name__ == "__main__":
    guess_number()